//package com.touchfired.common.event.handler.impl;
//
//import com.touchfired.common.constants.*;
//import com.touchfired.common.context.ServerContext;
//import com.touchfired.common.message.BaseMessage;
//import com.touchfired.common.message.transfer.MessageSender;
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandlerContext;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.LinkedList;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * @Description 连接成功事件码处理器
// * @Author 幸佳俊
// */
//@Component
//public class EventCodeRoomPaddingHandler extends BaseEventCodeHandler {
//
//    @Autowired
//    private ServerContext serverContext;
//
//    public EventCodeRoomPaddingHandler() {
//        super(EventCode.ROOM_PADDING);
//    }
//
//    @Override
//    public EventCodeHandler doHandle(ChannelHandlerContext ctx, ClientInfo clientInfo, BaseMessage message) throws Exception {
//        String roomId = clientInfo.getRoomId();
//        RoomInfo roomInfo = serverContext.getRoomInfo(roomId);
//        if (roomInfo == null) {
//            return null;
//        }
//
//        String content = message.getContent();
//        if (GlobalConstants.BACK.equalsIgnoreCase(content)) {
//            return eventHandle(ctx, clientInfo, message, EventCode.ROOM_QUIT);
//        }
//
//        // 规则提示
//        LinkedList<String> roomClients = roomInfo.getRoomClients();
//        List<ClientInfo> clientInfoList = roomClients.stream().map(serverContext::getClientInfo).collect(Collectors.toList());
//        GameRule gameRule = roomInfo.getGameRule();
//        String roomBuffer = "\n" +
//                roomInfo.getRoomName() + "[房间号" + roomInfo.getRoomId() + "]\n" +
//                gameRule.getRulesAppend() + "\n" +
//                "当前人数/最大人数：" + roomClients.size() + "/" + gameRule.getPlayerNum() + "（人满自动开始）\n" +
//                "当前玩家：" + clientInfoList.stream().map(ClientInfo::getName).collect(Collectors.toList()).toString() + "\n" +
//                "等待玩家加入中...\n" +
//                "[注]输入‘" + GlobalConstants.BACK + "’退出房间。";
//
//        // 开始（房间人数满）
//        List<Channel> clientsChannel = clientInfoList.stream().map(ClientInfo::getChannel).collect(Collectors.toList());
//        MessageSender.info(clientsChannel, message, roomBuffer);
//        if (gameRule.getPlayerNum() == roomClients.size()) {
//            MessageSender.info(clientsChannel, message, "游戏准备中，请稍后...");
//            return eventHandle(ctx, clientInfo, message, EventCode.GAME_STARTED);
//        }
//        return this;
//    }
//}
